home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 240 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: doug@monet.ads.com (Doug Morgan)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.os.ms-windows.programmer.misc
  4. Subject: Re: STL loops through a list with one element more than once!  Why?
  5. Date: 2 Jan 1996 20:31:03 -0000
  6. Organization: Booz-Allen & Hamilton
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4cc4m7$9v8@netlab.cs.rpi.edu>
  10. References: <4c1n8o$2jn@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12.  
  13. X-Original-Date: 02 Jan 1996 18:54:44 GMT
  14.  
  15. In article <4c1n8o$2jn@netlab.cs.rpi.edu> Bowden Wise <wiseb@cs.rpi.edu> writes:
  16. >...
  17. >    for (_itemIter  =   _itemList.begin();
  18. >         _itemIter  !=  _itemList.end();
  19. >         _itemIter++)
  20. >    {
  21. >...
  22. >       _itemList.erase (_itemIter);
  23. >    }
  24. > ...
  25. > Any ideas why the _itemIter != _itemList.end() test of the for
  26. > loop is failing?  Anyone else encountered this?
  27.  
  28. The erase() invalidates _itemIter.  Continuing the loop is therefore
  29. invalid.  Use _itemList.erase(_itemList.begin(), _itemList.end())
  30. instead.
  31.  
  32. Doug
  33. ----------
  34. Doug Morgan         TEL: (415) 960-7444 Booz-Allen & Hamilton, Inc. 
  35. doug@ads.com (UNIX) FAX: (415) 960-7500 1500 Plymouth St.            
  36. morgan_doug@bah.com (MS-Mail)           Mountain View, CA 94043-1230
  37. ----------
  38.  
  39.     [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
  40.     [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
  41.     [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
  42.     [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
  43.